home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / sort / Source / sortWindow.c < prev    next >
Text File  |  1993-06-17  |  3KB  |  162 lines

  1. /*****
  2.  * sortWindow.c
  3.  *
  4.  *
  5.  *****/
  6. #include <Quickdraw.h>
  7. #include <Dialogs.h>
  8. #include <OSUtils.h>
  9.  
  10. #ifdef THINK_C
  11. #include <Think.h>
  12. #endif /* THINK_C */
  13.  
  14. #include "sortWindow.h"
  15. #include "sortMenus.h"
  16. #include "sort.h"
  17.  
  18. WindowPtr    sortWindow;
  19. Rect        dragRect;
  20. Rect        windowBounds;
  21. Rect r;
  22. short height;
  23. Boolean sorting;
  24.  
  25. /****
  26.  * SetUpWindow()
  27.  *
  28.  *    Create the sort window, and open it.
  29.  *
  30.  ****/
  31.  
  32. void SetUpWindow(void)
  33.  
  34. {
  35. #ifdef THINK_C
  36.     windowBounds = screenBits.bounds;
  37. #else /* applec */
  38.     windowBounds = qd.screenBits.bounds;
  39. #endif /* applec */
  40.  
  41.     windowBounds.top += 20;
  42.  
  43.     sortWindow = NewWindow(0L, &windowBounds, "\pSort", true, plainDBox, (WindowPtr) -1L, true, 0);
  44.     SetPort(sortWindow);
  45.  
  46.     height=(((windowBounds.bottom - windowBounds.top) - numdataitems)) / (numdataitems + 1);
  47.     
  48. }
  49. /* end SetUpWindow */
  50.  
  51.  
  52. /*****
  53.  * Drawsort()
  54.  *
  55.  *    Draws the sort.
  56.  *
  57.  *****/
  58.  
  59. void DrawSort(short active)
  60. {
  61. #pragma unused (active)
  62.     long count;
  63.  
  64.     if (((WindowPeek) sortWindow)->visible)    {
  65.         SetPort(sortWindow);
  66.         for (count = 0; count < numdataitems; count++) {
  67.                 eraseitem(count);
  68.             drawitem(count);
  69.         }
  70.     }
  71.  
  72. }
  73. /* end Drawsort */
  74.  
  75. void myHilite(long item)
  76. {
  77.     WindowPtr w;
  78.     
  79.     if ((((WindowPeek) sortWindow)->visible)) {
  80.         GetPort(&w);
  81.         SetPort(sortWindow);
  82.     
  83.         r.left = 5;
  84.         r.top = item * (height + 1) + 5;
  85.         r.right = sortdata[item] + r.left;
  86.         r.bottom = r.top + height;
  87.         PaintRoundRect(&r, height, height);
  88.         SetPort(w);
  89.     }
  90. }
  91.  
  92. void unhilite(long item)
  93. {
  94.     WindowPtr w;
  95.     
  96.     if ((((WindowPeek) sortWindow)->visible))    {
  97.         GetPort(&w);
  98.         SetPort(sortWindow);
  99.     
  100.         r.left = 5;
  101.         r.top = item * (height + 1) + 5;
  102.         r.right = sortdata[item] + r.left;
  103.         r.bottom = r.top + height;
  104.         EraseRoundRect(&r, height, height);
  105.         FrameRoundRect(&r, height, height);
  106.         SetPort(w);
  107.     }
  108. }
  109.  
  110. void drawitem(long item)
  111. {
  112.     WindowPtr w;
  113.     
  114.     if (((WindowPeek) sortWindow)->visible)    {
  115.         GetPort(&w);
  116.         SetPort(sortWindow);
  117.     
  118.         r.left = 5;
  119.         r.top = item * (height + 1) + 5;
  120.         r.right = sortdata[item] + r.left;
  121.         r.bottom = r.top + height;
  122.         FrameRoundRect(&r, height, height);
  123.         SetPort(w);
  124.     }
  125. }
  126.  
  127.  
  128.  
  129. void eraseitem(long item)
  130. {
  131.     WindowPtr w;
  132.  
  133.     if (((WindowPeek) sortWindow)->visible) {
  134.         GetPort(&w);
  135.         SetPort(sortWindow);
  136.     
  137.         r.left = 5;
  138.         r.top = item * (height + 1) + 5;
  139.         r.right = sortdata[item] + r.left;
  140.         r.bottom = r.top + height;
  141.         EraseRoundRect(&r, height, height);
  142.         SetPort(w);
  143.     }
  144. }
  145.  
  146. void do_hilitedelay()
  147. {
  148.     long dummy;
  149.  
  150.     if ((((WindowPeek) sortWindow)->visible) && (!stop_sort))    {
  151.         Delay(hilitedelay, &dummy);
  152.     }
  153. }
  154.  
  155. void do_unhilitedelay()
  156. {
  157.     long dummy;
  158.  
  159.     if ((((WindowPeek) sortWindow)->visible) && (!stop_sort))    {
  160.         Delay(unhilitedelay, &dummy);
  161.     }
  162. }